package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.mapper.YaopinMapper;
import com.jiyun.model.xitong.Yaopin;
import com.jiyun.service.IYaopinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-24
 */
@Service
public class YaopinServiceImpl extends ServiceImpl<YaopinMapper, Yaopin> implements IYaopinService {
        @Autowired
        private YaopinMapper yaopinMapper;
        @Override
        public Page<Yaopin> findAll(Integer pageNum, Integer pageSize, Yaopin yaopin) {
                Page<Yaopin> yaopinPage = new Page<>(pageNum, pageSize);
                LambdaQueryWrapper<Yaopin> yaopinLambdaQueryWrapper= new LambdaQueryWrapper<>();
                yaopinLambdaQueryWrapper.like(StringUtils.isNotBlank(yaopin.getName()), Yaopin::getName, yaopin.getName());
                return      yaopinMapper.selectPage(yaopinPage,yaopinLambdaQueryWrapper);
        }

        @Override
        public Integer add(Yaopin yaopin) {
                Yaopin yaopin1= new Yaopin();
                yaopin1.setName(yaopin.getName());
                yaopin1.setStatus(1);
                yaopin1.setUserId(1);
                yaopin1.setType(yaopin.getType());
                yaopin1.setMs(yaopin.getMs());
                yaopin1.setTimes(new Date());
                yaopin1.setCreatetime(new Date());
                yaopin1.setImg(yaopin.getImg());
                yaopin1.setNum(100);
                yaopin1.setXuhao(yaopin.getXuhao());
                return yaopinMapper.insert(yaopin1);
        }

        @Override
        public Integer updates(Yaopin yaopin) {
                return yaopinMapper.updateById(yaopin);
        }

        @Override
        public Integer del(Integer id) {
                return yaopinMapper.deleteById(id);
        }

}
